package bishi;

import java.util.ArrayList;
import java.util.Scanner;

/**
 * @Author liuhaoqi
 * @Date 2020/9/6 14:31
 * @Version 1.0
 */
public class Zhaoyin02 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[][] arr = new int[n][n];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                arr[i][j] = scanner.nextInt();
            }
        }
        int start = scanner.nextInt();

        for (int i = 0; i < arr[start].length; i++) {
            if (arr[start][i] != 0) {
                System.out.println(dfs(arr,start,i));
            }
        }
    }

    public static boolean dfs(int[][] arr,int currow,int curnode) {
        ArrayList<Integer> list = new ArrayList<>();
        if (curnode == 0) {
            return false;
        }
        for (int i = 0; i < arr.length; i++) {
            boolean flag = dfs(arr, curnode, arr[curnode][i]);
            if (!flag) {
                continue;
            }
            list.add(currow);
            if (currow == curnode) {
                System.out.println(list.toString());
            }
        }
        return false;
    }
}
